<%@ page language="java" import="java.util.*" pageEncoding="utf8" %>
<%@ page import="com.niit.bc.bean.*" %>
<%@ page import="com.niit.bc.util.web.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<script type="text/javascript">
    function orderChange() {
        var checkByValue = document.form1.checkBy.value;
        var sub = "checkBy=";
        var bookListUrl = document.getElementById("bookListUrl").value;
        var s = bookListUrl.indexOf(sub);
//alert(s);
        if (s == -1) {
            bookListUrl += "&checkBy=" + checkByValue;
        } else {
            bookListUrl = bookListUrl.substring(0, parseInt(s));
            bookListUrl += "checkBy=" + checkByValue;
//alert(bookListUrl);
        }
//alert(bookListUrl) ;
        window.location.href = bookListUrl;
    }
</script>
<div class="right">
    <div class="right1">
        <h3>
            <form class="keywordform" action="SearchBook" method="post">
                <img src="images/icon_search.gif" align="absmiddle"/><strong>我要找图书：</strong>
                <input class="kw" id="key" name="key" value="请输入要查找的书名"
                       onfocus="if(this.value=='请输入要查找的书名'){this.value='';}">
                <input class="fcsearch" type="submit" value="查找">
            </form>
        </h3>
    </div>
    <div class="clear"></div>

    <div class="right2">
        <div class="fcsearch_tabs">
            <ul>
                <c:if test="${bookListUrl !=null }">
                    <Li class="slt"><span><a href='${bookListUrl }'>该类所有图书</a></span></li>
                </c:if>
                <Li><span><a href='#'>推荐图书</a></span></li>
                <Li><span><a href='#'>新书推荐</a></span></li>
                <Li><span><a href='#'>热门图书</a></span></li>
            </ul>
        </div>
        <div class="clear"></div>
        <div class="shopsxresult">
            <div class="totalnum"> 共有 <span><c:if test="${pageUtil != null }">${pageUtil.rowCount }</c:if></span>
                个宝贝符合您的需求
            </div>
            <form action="BookList" method="get" name="form1">
                <div class="sortby">请选择排序方式：
                    <c:if test="${bookListUrl !=null }">
                        <input type="hidden" id="bookListUrl" name="bookListUrl"
                               value="${bookListUrl }&pageCurr=${pageUtil.pageCurr}">
                    </c:if>

                    <select name="checkBy" style="padding:0px;MARGIN:0px; VERTICAL-ALIGN:middle;"
                            onchange="orderChange()">
                        <option selected value='0'>默认排序</option>
                        <option value='1'>价格从高到低</option>
                        <option value='2'>价格从低到高</option>
                        <option value='3'>最近上架商品</option>
                    </select>
                    <c:if test="${list !=null }">
                        快捷方式
                        <a href='BookList?${list }&pageCurr=1&checkBy=2'>价格</a>
                        <a href='BookList?${list }&pageCurr=1&checkBy=3'>上架</a>
                    </c:if>
                </div>
            </form>
        </div>
        <div class="clear"></div>
        <%
            if (request.getAttribute("msg") != null) {
                out.println("<script language=\"javascript\">alert('" + request.getAttribute("msg").toString() + "')</script>");
            }
        %>
        <div class="shoplisting">
            <ul>
                <%
                    List <BookBean> bookList = null;
                    BookBean book = null;
                    if (request.getAttribute(Constants.BOOKLIST) != null) {
                        bookList = (List <BookBean>) request.getAttribute(Constants.BOOKLIST);
                        if (bookList != null && bookList.size() != 0) {
                            for (int i = 0; i < bookList.size(); i++) {
                                book = bookList.get(i);
                %>
                <li onMouseOver="this.className='property2_hover'" onMouseOut="this.className='property2'">
                    <div class="photo"><a href="ShowBook?bookId=<%=book.getBookId() %>" target="_blank"
                                          title="<%=book.getBookName()%>"><img alt="<%=book.getBookName()%>"
                                                                               src="<%=book.getBookPhoto()%>"></a></div>
                    <div class="details">
                        <h3>￥<%=book.getBookPrice()%>元</h3>
                        <h4 align="center"><a title="<%=book.getBookName()%>"
                                              href="ShowBook?bookId=<%=book.getBookId() %>"
                                              target=_blank><%=book.getBookName() %>
                        </a></h4>
                    </div>
                </li>
                <%
                        }
                    }
                } else {
                %>
                <ul>
                    <li>温馨提示：</li>
                    <li>该书城暂时没有该类图书了，请查阅其它类图书</li>
                </ul>
                <%} %>
            </ul>
        </div>
        <c:if test="${bookListUrl !=null }">
            <div class="multipage">
                <div id='fenye' class='fenye'>
                    <table style="border:0px; float :right">
                        <c:if test="${pageUtil != null }">
                            <tr>
                                <td>
                                    共${pageUtil.pageCount}页&nbsp;&nbsp;&nbsp;共${pageUtil.rowCount}条记录&nbsp;&nbsp;&nbsp;第${pageUtil.pageCurr}页&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                            </tr>
                            <c:if test="${pageUtil.pageCount == 1 }">
                                <td>
                                    每页显示15条记录
                                </td>
                            </c:if>
                            <c:if test="${pageUtil.pageCount != 1 }">
                                <td>
                                    <c:if test="${pageUtil.pageCurr == 1 }">
                                        <a href="${bookListUrl }&pageCurr=${pageUtil.pageCurr+1}" class="prev">下一页</a>
                                        <a href="${bookListUrl }&pageCurr=${pageUtil.pageCount}" class="prev">末页</a>
                                    </c:if>

                                    <c:if test="${pageUtil.pageCurr < pageUtil.pageCount && pageUtil.pageCurr>1}">
                                        <a href="${bookListUrl }&pageCurr=1" class="prev">首页</a>
                                        <a href="${bookListUrl }&pageCurr=${pageUtil.pageCurr-1}" class="prev"> 上一页 </a>
                                        <a href="${bookListUrl }&pageCurr=${pageUtil.pageCurr+1}" class="prev">下一页</a>
                                        <a href="${bookListUrl }&pageCurr=${pageUtil.pageCount}" class="prev">末页</a>
                                    </c:if>

                                    <c:if test="${pageUtil.pageCurr == pageUtil.pageCount }">
                                        <a href="${bookListUrl }&pageCurr=1" class="prev">首页</a>
                                        <a href="${bookListUrl }&pageCurr=${pageUtil.pageCurr-1}" class="prev"> 上一页 </a>
                                    </c:if>

                                </td>
                            </c:if>
                        </c:if>
                    </table>
                </div>
            </div>
        </c:if>
    </div>
</div>
<div class="clear"></div>